package com.ccpdown.util.chkPackage;

import java.util.ArrayList;
import java.util.List;

import com.ccpdown.vo.Software;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;

public class ChkApplicationUitl {


	//获得已安装软件的包的列表
	public ArrayList<Software> getInstalledApps(Context context,boolean getSysPackages) {
	    ArrayList<Software> res = new ArrayList<Software>();  
	    PackageManager pm=context.getPackageManager();
	    List<PackageInfo> packs = pm.getInstalledPackages(0);
	    for(int i=0;i<packs.size();i++) {
	        PackageInfo p = packs.get(i);
	        if ((!getSysPackages) && (p.versionName == null)) {
	            continue ;
	        }
	        Software newInfo = new Software();
	        newInfo.softName= p.applicationInfo.loadLabel(pm).toString();
	        newInfo.packagename = p.packageName;
	        newInfo.version = p.versionName;
	        newInfo.versionCode = p.versionCode;
	        newInfo.icon = p.applicationInfo.loadIcon(pm);
	        res.add(newInfo);
	    }
	    return res; 
	}

	/** 获取未安装的APK信息  
     * @param context  
     * @param archiveFilePath APK文件的路径。如：/sdcard/download/XX.apk  
     */  
    public void getUninatllApkInfo(Context context, String archiveFilePath){   
        PackageManager pm = context.getPackageManager();   
        PackageInfo info = pm.getPackageArchiveInfo(archiveFilePath, PackageManager.GET_ACTIVITIES);   
        if(info != null){   
            ApplicationInfo appInfo = info.applicationInfo;   
            String appName = pm.getApplicationLabel(appInfo).toString();   
            String packageName = appInfo.packageName;   
            Drawable icon = pm.getApplicationIcon(appInfo);   
        }   
    } 

}
